package com.ruoyi.flowable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.flowable.domain.WfDeployTaskCopy;
import com.ruoyi.flowable.service.IWfDeployTaskCopyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 流程实例节点抄送对象Controller
 *
 * @author ruoyi
 * @date 2024-03-31
 */
@RestController
@RequestMapping("/flowable/taskCopy")
public class WfDeployTaskCopyController extends BaseController {

    @Autowired
    private IWfDeployTaskCopyService wfDeployTaskCopyService;

    /**
     * 查询流程实例节点抄送对象列表
     *
     * @param wfDeployTaskCopy 参数
     * @return 列表
     */
    @PreAuthorize("@ss.hasPermi('flowable:taskCopy:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfDeployTaskCopy wfDeployTaskCopy) {
        startPage();
        LambdaQueryWrapper<WfDeployTaskCopy> lqw = new LambdaQueryWrapper<WfDeployTaskCopy>();
        if (StringUtils.isNotBlank(wfDeployTaskCopy.getNodeName())) {
            lqw.like(WfDeployTaskCopy::getNodeName, wfDeployTaskCopy.getNodeName());
        }
        if (StringUtils.isNotBlank(wfDeployTaskCopy.getCopyList())) {
            lqw.eq(WfDeployTaskCopy::getCopyList, wfDeployTaskCopy.getCopyList());
        }
        List<WfDeployTaskCopy> list = wfDeployTaskCopyService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出流程实例节点抄送对象列表
     */
    @PreAuthorize("@ss.hasPermi('flowable:taskCopy:export')")
    @Log(title = "流程实例节点抄送对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfDeployTaskCopy wfDeployTaskCopy) {
        LambdaQueryWrapper<WfDeployTaskCopy> lqw = new LambdaQueryWrapper<WfDeployTaskCopy>();
        if (StringUtils.isNotBlank(wfDeployTaskCopy.getNodeName())) {
            lqw.like(WfDeployTaskCopy::getNodeName, wfDeployTaskCopy.getNodeName());
        }
        if (StringUtils.isNotBlank(wfDeployTaskCopy.getCopyList())) {
            lqw.eq(WfDeployTaskCopy::getCopyList, wfDeployTaskCopy.getCopyList());
        }
        List<WfDeployTaskCopy> list = wfDeployTaskCopyService.list(lqw);
        ExcelUtil<WfDeployTaskCopy> util = new ExcelUtil<WfDeployTaskCopy>(WfDeployTaskCopy.class);
        util.exportExcel(response, list, "流程实例节点抄送对象数据");
    }

    /**
     * 获取流程实例节点抄送对象详细信息
     *
     * @param deployId id
     * @return 详细信息
     */
    @PreAuthorize("@ss.hasPermi('flowable:taskCopy:query')")
    @GetMapping(value = "/{deployId}")
    public AjaxResult getInfo(@PathVariable("deployId") String deployId) {
        return success(wfDeployTaskCopyService.getById(deployId));
    }

    /**
     * 新增流程实例节点抄送对象
     *
     * @param wfDeployTaskCopy 参数
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('flowable:taskCopy:add')")
    @Log(title = "流程实例节点抄送对象", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfDeployTaskCopy wfDeployTaskCopy) {
        return toAjax(wfDeployTaskCopyService.save(wfDeployTaskCopy) ? 1 : 0);
    }

    /**
     * 修改流程实例节点抄送对象
     *
     * @param wfDeployTaskCopy 参数
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('flowable:taskCopy:edit')")
    @Log(title = "流程实例节点抄送对象", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfDeployTaskCopy wfDeployTaskCopy) {
        return toAjax(wfDeployTaskCopyService.updateById(wfDeployTaskCopy) ? 1 : 0);
    }

    /**
     * 删除流程实例节点抄送对象
     *
     * @param deployIds 主键id数组
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('flowable:taskCopy:remove')")
    @Log(title = "流程实例节点抄送对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deployIds}")
    public AjaxResult remove(@PathVariable String[] deployIds) {
        return toAjax(wfDeployTaskCopyService.removeByIds(Arrays.asList(deployIds)) ? 1 : 0);
    }
}
